<template>
	<view class="p30">
		<view class=" bg-fff radius20  pl20 pr20 pb42">
			<u-form :model="form" ref="uForm" label-width="auto" :label-style="{color: '#666'}">
				<u-form-item label="姓名">
					<u-input v-model="form.name" placeholder="请填写姓名" inputAlign="right" />
				</u-form-item>
				<u-form-item label="手机号码">
					<u-input v-model="form.mobile" maxlength="11" type="number" placeholder="请填写手机号"
						inputAlign="right" />
				</u-form-item>

				<auto-select ref="list" api="/system/basic/getRegion" @confirm="confirm" labelName="name"
					childName="child" valueName="id" />

				<u-form-item label="选择地址">
					<u-input placeholder="请选择地址" v-model="form.city_name" @click="$refs.list.open()" type="select"
						inputAlign="right" />
				</u-form-item>
				<u-form-item label="详细地址">
					<u-input v-model="form.address" placeholder="请填写详细地址" inputAlign="right" />
				</u-form-item>
			</u-form>
			<view class=" h84 radius12 bg-zs color-fff flex row-center mt60" @click="submit">
				{{form.id?'修改':'添加'}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					member_id: '',
					id: '', //	字符串	必填	-	-	地址id
					name: '', //	字符串	必填	-	-	姓名
					mobile: '', //	字符串	必填	-	-	手机号
					address: '', //	字符串	必填	-	-	收件地址
					city_id: "",
					city_name: ''
				},
			};
		},
		onLoad(e) {
			if (e.id) {
				this.getData()
				uni.setNavigationBarTitle({
					title: '修改地址'
				})
			}
		},
		methods: {
			getData() {
				this.$request('/member/my/addressInfo', this.$params).then(res => {
					for (let key in this.form) {
						this.form[key] = res.data[key]
					}
				})
			},
			confirm(e) {
				this.form.city_name = e.map(e => e.label).join(' ')
				let item = e.reverse()[0]
				this.form.city_id = item.value
			},
			submit() {
				let api = '/member/my/addressAdd'
				if (this.form.id) api = '/member/my/addressEdit'
				this.$request(api, this.form).then(res => {
					this.$msg(res.msg)
					setTimeout(this.$navBack, 1000)
				})
			}
		}
	}
</script>

<style lang="scss">

</style>